package top.shen33.yang;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class EventBusClient {


    public static void main(String[] args) {


        ExecutorService pool = Executors.newFixedThreadPool(10);
//        EventBus eventBus = new EventBus();
        AsyncEventBus eventBus = new AsyncEventBus("asyncEventBus",pool);

        eventBus.register(new Object(){

            @Subscribe
            @AllowConcurrentEvents
            public void handleUserInfoChangeEvent(UserInfoChangeEvent userInfoChangeEvent){
                System.out.println("处理用户信息变化事件：" + userInfoChangeEvent.getUserName());
            }

            @Subscribe
            @AllowConcurrentEvents
            public void handleUserInfoChangeEvent(BaseEventBusEvent baseEventBusEvent){
                System.out.println("所有事件的父类");
            }

        });



        eventBus.post(new UserInfoChangeEvent("apple"));


    }


    static class BaseEventBusEvent{

    }

    static class UserInfoChangeEvent extends BaseEventBusEvent{
        private String userName;

        public UserInfoChangeEvent(String userName) {
            this.userName = userName;
        }

        public String getUserName() {
            return userName;
        }
    }

}
